package tp.pr4;


import tp.pr4.instructions.*;
import tp.pr4.instructions.exceptions.WrongInstructionFormatException;

public class Interpreter {
	
	static private Instruction[] instructionlist=
	{
		new DropInstruction(),
		new HelpInstruction(),
		new MoveInstruction(),
		new OperateInstruction(),
		new PickInstruction(),
		new QuitInstruction(),
		new RadarInstruction(),
		new ScanInstruction(),
		new TurnInstruction(),
	};
	
	public static Instruction generateInstruction(java.lang.String line)
            throws WrongInstructionFormatException
	{
		for (Instruction instruction : instructionlist)
		{
			try{
				return instruction.parse(line);
			}catch(Exception e){}
		}
		throw new WrongInstructionFormatException("WALL·E says: I do not understand. Please repeat");
	}	
	
	public static java.lang.String interpreterHelp()
	{
		String LINE_SEPARATOR = System.getProperty("line.separator");
		return("The valid instructions for WALL-E are:"+LINE_SEPARATOR +
			"     MOVE | MOVER"+LINE_SEPARATOR +
			"     TURN <LEFT | RIGHT>"+LINE_SEPARATOR +
			"     PICK <ITEM>"+LINE_SEPARATOR +
			"     SCAN [ <ITEM> ]"+LINE_SEPARATOR +
			"     OPERATE <ITEM>"+LINE_SEPARATOR +
			"     RADAR"+LINE_SEPARATOR +
			"     DROP <ITEM>"+LINE_SEPARATOR +
			"     HELP | AYUDA"+LINE_SEPARATOR +
			"     QUIT");
	}	  	

}
